#include "stdafx.h"
#include "TestSpecPersist.h"
#include "SpecPersist.h"
#include "Spec.h"
#include "DataBasebase.h"


using namespace PDMS::PDMSDBIF;
using namespace PDMS::SpecFrame;

CPPUNIT_TEST_SUITE_REGISTRATION( TestSpecPersist );


TestSpecPersist::TestSpecPersist()
{
}


TestSpecPersist::~TestSpecPersist()
{
}

void TestSpecPersist::TestRetrieve()
{
	DatabaseBase base( GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) );
	base.DataSource( _T("D:\\SpecificationTemplate.mdb") );
	SpecPersist* pSpecPersist =  new SpecPersist;
	pSpecPersist->SetDatabase(&base);
	
	Spec* pSpec = new Spec;
	pSpec->Id( UeObjectId(12, 102) );
	Persistable* pObj = static_cast<Persistable*>(pSpec);

	UESoft::ErrorStatus es = pSpecPersist->Retrieve( pObj );
	CPPUNIT_ASSERT( es == UESoft::eOk );
	delete pSpec;
	delete pSpecPersist;
}

void TestSpecPersist::TestUpdate()
{
	Spec* pSpec = new Spec;
	pSpec->Id( UeObjectId(33, 77) );

	DatabaseBase base( GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) );
	base.DataSource( _T("D:\\SpecificationTemplate.mdb") );
	SpecPersist* pSpecPersist =  new SpecPersist;
	pSpecPersist->SetDatabase(&base);
	
	pSpec->SetMatID( 765 );
	pSpec->SetMatref( "sdfls" );
	
	pSpecPersist->Update( pSpec );
	base.UpdateAll();
	base.CloseAll();
	delete pSpec;
	delete pSpecPersist;
}


void TestSpecPersist::TestCreate()
{
	Spec* pSpec = new Spec;	
	pSpec->Id( UeObjectId(33, 105) );
		
	DatabaseBase base( GET_REGISTER( DatabaseElementFactory, Design_VersionOne ) );
	base.DataSource( _T("D:\\SpecificationTemplate.mdb") );
	SpecPersist* pSpecPersist =  new SpecPersist;
	pSpecPersist->SetDatabase(&base);
		
	pSpec->Name("slkjdl;ll");
	pSpec->SetMatref( "111" );
	pSpec->SetMatID( 354 );
	pSpec->SetFluidID( 124 );
	pSpec->SetFluidref( "sdfl;a" );
	
	pSpecPersist->Create( pSpec );
	base.UpdateAll();
	base.CloseAll();
	
	delete pSpec;
	delete pSpecPersist;
	
}